package vip.denglei.company.controller.app;

import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import vip.denglei.company.service.app.OssTemplate;
import vip.denglei.company.util.HttpResult;
import vip.denglei.company.util.minio.OssFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

@RequestMapping(value = "/app/fileUpload")
@RestController
@Slf4j
public class FileUploadController {
    @Resource
    private OssTemplate ossTemplate;

    @PostMapping("save/fileUpload")
    public HttpResult saveFileUpload(@RequestParam("file") MultipartFile file, @RequestParam("folderName") String folderName, @RequestParam("fileName") String fileName, HttpServletRequest request) {
        log.info("FileUploadController saveFileUpload 参数 folderName:{},fileName:{}", folderName, fileName);
        OssFile ossFile = ossTemplate.upLoadFile(folderName, fileName, file);
        ossFile.setDomain(ossFile.getDomain().replace("http://124.223.102.36:9000", "https://hbcaiyu.cn/file"));
        return HttpResult.success(ossFile);
    }
}
